<?php

namespace app\mall\controller\api\goods;

use app\mall\enum\StatusEnum;
use app\mall\exceptions\ApiException;
use app\mall\model\MallGoods;

class Base extends \app\mall\controller\api\Base
{

    /**
     * @param array $field
     * @throws \app\mall\exceptions\BaseException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function getDataFromRequest($field = [])
    {
        $id = $this->request->get('id');
        if (!$id) {
            ApiException::throws(ApiException::$requireArgs);
        }
        $model = MallGoods::where('status', StatusEnum::VALID);
        if($field){
            $model->field($field);
        }
        $info = $model->find($id);
        if (!$info) {
            ApiException::throws(ApiException::$infoNotFound);
        }
        return $info;
    }

}